<?php
namespace Home\Controller;
use Think\Controller;
class SetController extends CommonController {
	//设置首页
    public function index(){
        // var_dump($_SERVER);
    	//获取登录用户的id
    	$uid = $_SESSION['uid'];

    	$user = M('user')->find($uid);

    	$this->assign('user',$user);
    	
        $this->display();
        
    }
    public function edit()
    {
    	$data = I('post.');

    	$User = D("User"); // 实例化User对象

		if (!$User->create($data,2)){ // 指定新增数据
		     // 如果创建失败 表示验证没有通过 输出错误提示信息
		     $this->ajaxReturn(['error'=>1,'info'=>$User->getError()]);
		}else{

			// "select * from user where eamil='emil' and uid <> 8";

			$res = M('user')->where(['email'=>$data['email'],'uid'=>['neq',$_SESSION['uid']]])->select();

			if($res){
				$this->ajaxReturn(['error'=>1,'info'=>"邮箱已存在"]);
			}

			$res = M('user')->where(['nickname'=>$data['nickname'],'uid'=>['neq',$_SESSION['uid']]])->select();

			if($res){
				$this->ajaxReturn(['error'=>1,'info'=>"昵称已存在"]);
			}


			M('user')->where(['uid'=>$_SESSION['uid']])->save($data);

			$_SESSION['nickname'] = $data['nickname'];

			$this->ajaxReturn(['error'=>0,'info'=>"修改成功"]);

		     // 验证通过 可以进行其他数据操作
		}
    }

    public function editpass()
    {
    	$data = I('post.');

    	$data['password'] = md5($data['password']);

    	M('user')->where(['uid'=>$_SESSION['uid']])->save($data);
    	$this->ajaxReturn(['error'=>0,'info'=>"修改成功"]);
    }
    public function upload()
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            echo "失败";
        }else{// 上传成功
            // var_dump($info);
            $face = "Uploads/".$info['face']['savepath'].$info['face']['savename'];

            M('user')->where(['uid'=>$_SESSION['uid']])->save(['face'=>$face]);

            unlink($_SESSION['face']);

            $_SESSION['face'] =  $face;

           echo "成功"; 
            
        }
    }

    public function sendmail()
    {
        $conten =<<<xbs
        <div><includetail><div style="padding:40px;"><div class="promotion_container"><div class="promotion_img promotion_banner"><div class="container"><div class="banner_title">免费注册腾讯企业邮</div>
                <div class="banner_sub_title">快速开通，邮件一键搬家</div>
                <a class="open_btn" href="https://exmail.qq.com/signupfree?refer=invite_freereg_ck&amp;action=report_free_signup" target="_blank" id="freeReg">立即开通</a>
            </div>
        </div>
        <div style="margin: 0 55px; color: #000;">
            <div class="functions">
                <h1 class="h1_title">你将获得以下邮箱功能</h1>
                <ul class="p_list">
                    <li>
                        <div class="p_item">
                            <span class="promotion_img ico_capacity"></span>
                            <div class="p_caption">50个成员帐号</div>
                        </div>
                    </li>
                    <li style="margin-left: 73px;">
                        <div class="p_item">
                            <span class="promotion_img ico_domain"></span>
                            <div class="p_caption">每人2G邮箱容量</div>
                        </div>
                    </li>
                    <li style="margin-left: 75px;">
                        <div class="p_item">
                            <span class="promotion_img ico_approval"></span>
                            <div class="p_caption">2G企业网盘</div>
                        </div>
                    </li>
                    <li style="margin-left: 65px;">
                        <div class="p_item">
                            <span class="promotion_img ico_save"></span>
                            <div class="p_caption">丰富的企业管理功能</div>
                            <div class="more"><a href="https://exmail.qq.com/cgi-bin/readtemplate?t=new_index/index&amp;refer=invite_freereg_more_ck" target="_blank">了解更多&gt;</a></div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="btm">
                腾讯企业邮团队
            </div>
        </div>
    </div>
    <img src="//exmail.qq.com/cgi-bin/readtemplate?sid=k5P56or3DshNdnAp&amp;loc=qqmailedm,exmailivt,show,1" style="width:1px;height:1px;display:none;">
    <img src="//exmail.qq.com/cgi-bin/sellonlinestatic?type=nosession_statistics&amp;businame=mail_open_amount&amp;item=free_reg" style="width:1px;height:1px;display:none;">

</div></includetail></div><style>
      body{margin:0; padding:0;
            font-family: PingFangSC-Regular,BlinkMacSystemFont,Helvetica,"lucida Grande","PingFang SC",SCHeiti,"Microsoft YaHei";}
        p{margin:0 0;}
        h1, h2, th{
            font-weight: normal;
        }
        .promotion_container{
            font-weight: normal;
            color: #5A7184;
            font-size: 14px;
            text-align: center;
            background-color: #fff;
            margin:0 auto;
            width:800px;
            padding-bottom: 25px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
            overflow:hidden;
            _zoom:1;
        }
        .promotion_container a {
            text-decoration: none!important;
            color: #2a8ae2;
            cursor: pointer;
            outline: none;
        }
        .promotion_container a:hover {
            text-decoration: none;
        }
        .promotion_container .promotion_img{
            background-image: url(https://exmail.qq.com/zh_CN/htmledition/images/promotion/free_reg.png);
            background-size: 800px 660px ;
            width: 800px;
            height: 660px;
            margin:0px auto;
            background-repeat: no-repeat;
            display: inline-block;
        }
        .promotion_container .logo{
            background-image: url(https://exmail.qq.com/zh_CN/htmledition/images/promotion/logo.png);
            background-size: 97px 22px ;
            width: 97px;
            height: 22px;
            background-repeat: no-repeat;
            display: inline-block;
            position: relative;
            top: 16px;
            left: 16px;
            float: left;
        }
        @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min--moz-device-pixel-ratio: 2), only screen and (-o-min-device-pixel-ratio: 2), only screen and (min-device-pixel-ratio: 2), only screen and (min-resolution: 2dppx), only screen and (min-resolution: 192dpi) {
            .promotion_container .promotion_img {
                background-image: url(https://exmail.qq.com/zh_CN/htmledition/images/promotion/free_reg_2x.png);
            }
            .promotion_container .logo{
                background-image: url(https://exmail.qq.com/zh_CN/htmledition/images/promotion/logo_2x.png);
            }
        }
        .promotion_container .promotion_banner{
            background-position:  0 0;
            width: 800px;
            height: 300px;
        }
        .promotion_container .ico_capacity {
            background-position: 0 -308px;
            width: 82px;
            height: 82px;
        }
        .promotion_container .ico_domain {
            background-position: 0 -398px;
            width: 82px;
            height: 82px;
        }
        .promotion_container .ico_approval {
            background-position: 0 -488px;
            width: 82px;
            height: 82px;
        }
        .promotion_container .ico_save {
            background-position: 0 -578px;
            width: 82px;
            height: 82px;
        }
        .promotion_container .container{ color: #fff; margin-top: 65px; text-align: center;}
        .promotion_container .container .banner_title{font-size: 28px; line-height: 40px; font-weight: 300;  margin-bottom: 6px;}
        .promotion_container .container .banner_sub_title{font-size: 14px;  line-height: 14px;}
        .promotion_container .open_btn{width: 128px; height: 36px;   font-size: 16px; background-color: #2A8AE2; display: inline-block;  margin-top: 25px;
            color: inherit; line-height: 36px; text-align: center; }
        .promotion_container .functions{
            width: 690px;
            margin: 0 auto;
            border-bottom: 1px solid #E4E4E4;
        }
        .promotion_container .h1_title{
            text-align: left;
            font-size: 16px;
            font-weight: bold;
            margin-top: 30px;
            margin-left: 45px;
            margin-bottom: 24px;
            line-height: 22px;
        }
        .promotion_container .more{
            color: #2a8ae2;
            font-size: 12px;
            line-height: 17px;
        }
        .promotion_container .p_list{
            overflow: hidden;
            width: 613px;
            margin: 0px auto 24px;
            padding-left: 0px;
        }
        .promotion_container .p_list .p_item{ text-align: center;}
        .promotion_container .p_list li{
            float: left;
            list-style: none;
            text-align: left;
        }
        .promotion_container .p_caption{
            font-size: 14px;
            line-height: 30px;
            margin-top: 5px;
        }
        .promotion_container .btm{
            text-align: left;
            margin-top: 13px;
            color: #999;}
    </style>
xbs;

        xbsmail('327197843@qq.com',"测试邮件",$conten);

    }
}